﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;

namespace Maticsoft.Web.CERTI
{
    public partial class Modify : Page
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                if (Session["u"] == null)
                {
                    Page.ClientScript.RegisterStartupScript(this.GetType(), "", "if(top){top.location.href='../Login.aspx'}else{location.href='../Login.aspx'};", true);
                }

            }

            if (!Page.IsPostBack)
            {
                object ZSH = Request.QueryString["ZSH"];
                if (ZSH != null && ZSH.ToString().Length > 0)
                {
                    ShowInfo(ZSH.ToString().Trim());
                }
            }
        }

        private void ShowInfo(string zsh)
        {
            Maticsoft.BLL.CERTI bll = new Maticsoft.BLL.CERTI();
            Maticsoft.Model.CERTI model = bll.GetModel(zsh);
            this.txtZSH.Text = model.ZSH;
            this.txtJCS.Text = model.JCS;
            this.txtPM.Text = model.PM;
            this.txtJJZ.Text = model.JJZ;
            this.txtBM.Text = model.BM;
            this.txtBZ.Text = model.BZ;
            //this.txtCREATEDATE.Text=model.CREATEDATE;
            this.txtTEMP.Text = model.TEMP;

        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (this.txtZSH.Text.Trim().Length == 0)
            {
                strErr += "证书号不能为空！\\n";
            }
            //if(this.txtJCS.Text.Trim().Length==0)
            //{
            //    strErr+="金成色不能为空！\\n";	
            //}
            //if(this.txtPM.Text.Trim().Length==0)
            //{
            //    strErr+="品名不能为空！\\n";	
            //}
            //if(this.txtJJZ.Text.Trim().Length==0)
            //{
            //    strErr+="净金重不能为空！\\n";	
            //}
            //if(this.txtBM.Text.Trim().Length==0)
            //{
            //    strErr+="编码不能为空！\\n";	
            //}
            //if(this.txtBZ.Text.Trim().Length==0)
            //{
            //    strErr+="备注不能为空！\\n";	
            //}
            ////if(this.txtCREATEDATE.Text.Trim().Length==0)
            ////{
            ////    strErr+="创建时间不能为空！\\n";	
            ////}
            //if(this.txtTEMP.Text.Trim().Length==0)
            //{
            //    strErr+="临时信息不能为空！\\n";	
            //}

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            string ZSH = this.txtZSH.Text;
            string JCS = this.txtJCS.Text;
            string PM = this.txtPM.Text;
            string JJZ = this.txtJJZ.Text;
            string BM = this.txtBM.Text;
            string BZ = this.txtBZ.Text;
            //string CREATEDATE=this.txtCREATEDATE.Text;
            string TEMP = this.txtTEMP.Text;


            Maticsoft.Model.CERTI model = new Maticsoft.Model.CERTI();
            model.ZSH = ZSH;
            model.JCS = JCS;
            model.PM = PM;
            model.JJZ = JJZ;
            model.BM = BM;
            model.BZ = BZ;
            //model.CREATEDATE=CREATEDATE;
            model.TEMP = TEMP;

            Maticsoft.BLL.CERTI bll = new Maticsoft.BLL.CERTI();
            bll.Update(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "list.aspx");

        }


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
